In [1]:
import networkx as nx
import random

In [2]:
from mesa import Agent, Model
from mesa.time import RandomActivation

In [3]:
class NetworkAgent(Agent):
    def __init__(self, unique_id):
        self.unique_id = unique_id
    
    def step(self, model):
        # The agent step will go here
        pass
to setup-spatially-clustered-network let num-links (average-node-degree * number-of-nodes) / 2 while [count links < num-links ] [ ask one-of turtles [ let choice (min-one-of (other turtles with [not link-neighbor? myself]) [distance myself]) if choice != nobody [ create-link-with choice ] ] ] ; make the network look a little prettier repeat 10 [ layout-spring turtles links 0.3 (world-width / (sqrt number-of-nodes)) 1 ] end

In [13]:
class NetworkModel(Model):
    """A model with some number of agents"""
    def __init__(self, N, avg_node_degree):
        self.num_agents = N
        self.avg_node_degree = avg_node_degree
        self.schedule = RandomActivation(self)
        self.graph = None
                
        #create Graph
        num_links = (self.avg_node_degree * self.num_agents) / 2
        
        G = nx.dense_gnm_random_graph(self.num_agents, num_links)
        print(G.edges())
        
    def step(self):
        """Advance the model by one step."""
        self.schedule.step()

In [14]:
empty_model = NetworkModel(50, 4)
empty_model.step()


[(0, 12), (0, 4), (0, 44), (0, 36), (1, 18), (1, 34), (1, 14), (1, 15), (2, 8), (2, 32), (2, 31), (3, 18), (3, 22), (3, 7), (3, 43), (3, 46), (3, 31), (4, 18), (4, 25), (4, 15), (4, 45), (4, 31), (5, 44), (5, 13), (5, 30), (6, 42), (6, 44), (6, 38), (6, 15), (8, 42), (9, 49), (9, 20), (10, 32), (10, 21), (10, 40), (10, 30), (10, 46), (10, 47), (11, 19), (11, 31), (12, 17), (12, 30), (13, 33), (13, 38), (13, 39), (13, 49), (13, 45), (14, 36), (14, 37), (14, 39), (14, 45), (14, 30), (14, 47), (15, 37), (15, 49), (16, 34), (16, 42), (16, 21), (16, 30), (17, 36), (17, 26), (17, 27), (17, 47), (18, 46), (19, 48), (19, 33), (19, 40), (19, 27), (19, 28), (20, 40), (20, 21), (20, 22), (20, 37), (21, 48), (21, 36), (21, 43), (22, 48), (23, 43), (24, 32), (24, 34), (24, 43), (24, 44), (25, 32), (26, 35), (27, 44), (27, 38), (29, 40), (29, 45), (29, 38), (29, 31), (31, 42), (32, 40), (33, 40), (34, 37), (34, 39), (35, 38), (36, 42), (38, 49), (38, 41), (41, 44)]

In [59]:
import matplotlib.pyplot as plt
%matplotlib


Using matplotlib backend: TkAgg

In [60]:
G = model.graph
len(model.graph)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-60-f881fb4e6a5b> in <module>()
      1 G = model.graph
----> 2 len(model.graph)

TypeError: object of type 'NoneType' has no len()

In [ ]:


In [ ]:
3 = 3
4 = 6
5 = 10
6 = 15
20 = 190